﻿#include "PlatformProperty.h"

MAPPING_VALUE(sdb::AvailabilitySts, PropertyStatus, PropertyStatus::NotAvailable)
    MAPPING_ITEM(sdb::AvailabilitySts::Active, PropertyStatus::Active)
    MAPPING_ITEM(sdb::AvailabilitySts::NotActive, PropertyStatus::NotActive)
    MAPPING_ITEM(sdb::AvailabilitySts::Error, PropertyStatus::Error)
    MAPPING_ITEM(sdb::AvailabilitySts::NotAvailable, PropertyStatus::NotAvailable)
MAPPING_END

SYSTEM_READ_WRITE_PROPERTY(HVAC_MAX_AC_ON, bool) {
    builder.area(VehicleAreaSeat::ROW_1_LEFT | VehicleAreaSeat::ROW_1_RIGHT |
                 VehicleAreaSeat::ROW_2_LEFT | VehicleAreaSeat::ROW_2_RIGHT |
                 VehicleAreaSeat::ROW_2_CENTER)
            .initValue([]() { return false; })
            .withStatusBySignals([]([[maybe_unused]] const PropertyStatus &lastStatus) {
                sdb::AvailabilitySts availabilitySts = sdb::AvailabilitySts(SIGNAL.getPA_CL_MaxAC().availability);
                PropertyStatus status = mappingValue(availabilitySts, PropertyStatus::NotAvailable);
                VHALOG.d("HVAC_MAX_AC_ON zone_all availabilitySts is %d , status changed to: %d ", availabilitySts, status);
                return status;
            }, PASignal::PA_CL_MaxAC)
            .withValueBySignals([]([[maybe_unused]] const bool &last) {
                // RX信号变化时，重新计算功能值
                int data = SIGNAL.getPA_CL_MaxAC().data;
                VHALOG.d("HVAC_MAX_AC_ON zone_all value changed to: %d ", data);
                return data == 1 ? true : false;
            }, PASignal::PA_CL_MaxAC)
            .onSetProperty([](const bool value) {
                VHALOG.d("halOnSetProperty SET HVAC_MAX_AC_ON : %d", value);
                SIGNAL.setCB_CL_MaxAC(value ? sdb::OnOff1::On : sdb::OnOff1::Off);
            });
}
